package com.sport.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sport.common.core.domain.model.LoginUser;
import com.sport.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sport.common.annotation.Log;
import com.sport.common.core.controller.BaseController;
import com.sport.common.core.domain.AjaxResult;
import com.sport.common.enums.BusinessType;
import com.sport.system.domain.SportImg;
import com.sport.system.service.ISportImgService;
import com.sport.common.utils.poi.ExcelUtil;
import com.sport.common.core.page.TableDataInfo;

/**
 * 运动会图片Controller
 *
 * @author wyd
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/system/img")
public class SportImgController extends BaseController
{
    @Autowired
    private ISportImgService sportImgService;

    /**
     * 查询运动会图片列表
     */
//    @PreAuthorize("@ss.hasPermi('system:img:list')")
    @GetMapping("/list")
    public TableDataInfo list(SportImg sportImg)
    {
        startPage();
        List<SportImg> list = sportImgService.selectSportImgList(sportImg);
        return getDataTable(list);
    }

    /**
     * 导出运动会图片列表
     */
//    @PreAuthorize("@ss.hasPermi('system:img:export')")
    @Log(title = "运动会图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SportImg sportImg)
    {
        List<SportImg> list = sportImgService.selectSportImgList(sportImg);
        ExcelUtil<SportImg> util = new ExcelUtil<SportImg>(SportImg.class);
        util.exportExcel(response, list, "运动会图片数据");
    }

    /**
     * 获取运动会图片详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:img:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sportImgService.selectSportImgById(id));
    }

    /**
     * 新增运动会图片
     */
//    @PreAuthorize("@ss.hasPermi('system:img:add')")
    @Log(title = "运动会图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SportImg sportImg)
    {
        sportImg.setId(IdUtils.simpleUUID());
        return toAjax(sportImgService.insertSportImg(sportImg));
    }

    /**
     * 修改运动会图片
     */
//    @PreAuthorize("@ss.hasPermi('system:img:edit')")
    @Log(title = "运动会图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SportImg sportImg)
    {
        return toAjax(sportImgService.updateSportImg(sportImg));
    }

    /**
     * 删除运动会图片
     */
//    @PreAuthorize("@ss.hasPermi('system:img:remove')")
    @Log(title = "运动会图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sportImgService.deleteSportImgByIds(ids));
    }
}
